package com.smz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smz.entity.Settlement;
import com.smz.service.SettlementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api
@RestController
public class SettlementController {


    @Autowired
    private SettlementService settlementService;

    @ApiOperation("物流结算管理分页查询")
    @GetMapping("/settlement/{current}/{size}")
    public ResponseEntity<IPage<Settlement>> findSettlementPage(@PathVariable("current") int current,
                                                                @PathVariable("size") int size){
        IPage<Settlement> page = settlementService.findSettlementPage(current,size);
        return ResponseEntity.ok(page);
    }

    @ApiOperation("添加物流结算管理")
    @PostMapping("/settlement")
    public ResponseEntity<String> addSettlementPage(@RequestBody Settlement settlement){
        settlementService.saveOrUpdate(settlement);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("修改物流结算管理")
    @PutMapping("/settlement")
    public ResponseEntity<String> modifySettlement(@RequestBody Settlement settlement){
        settlementService.saveOrUpdate(settlement);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("删除物流结算管理")
    @DeleteMapping("/settlement/{id}")
    public ResponseEntity<String> removeSettlement(@PathVariable int id){
        settlementService.removeById(id);
        return ResponseEntity.ok("ok");
    }
}
